package com.xucia.jsponic.data;

import java.util.Map;
import java.util.WeakHashMap;

public class TransactionValue {
	Map<Transaction,Object> values = new WeakHashMap<Transaction,Object>();
	public TransactionValue(Object defaultValue) {
		values.put(Transaction.OUTSIDE, defaultValue);
	}
	public synchronized Object getValue() {
		Transaction trans = Transaction.currentTransaction();
		return values.containsKey(trans) ? values.get(trans) : values.get(Transaction.OUTSIDE);
	}
	public void setValue(Object value) {
		values.put(Transaction.currentTransaction(),value);
	}
	public boolean canReplace() {
		return values.keySet().size() == 1;
	}
}
